﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace TestCommunityMvvmToolkit.Controls
{
    public class AliveContentControl : ContentControl
    {
        public object? AliveContent
        {
            get { return (object?)GetValue(AliveContentProperty); }
            set { SetValue(AliveContentProperty, value); }
        }

        public static readonly DependencyProperty AliveContentProperty =
            DependencyProperty.Register("AliveContent", typeof(object), typeof(AliveContentControl), new PropertyMetadata(null, AliveContentChanged));

        private static void AliveContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var ele = (AliveContentControl)d;

            ele.Content = e.NewValue;
            ele.ContentTemplate = ViewAware.AttachDataTemplate(e.NewValue);
        }
    }
}
